package com.yanqu.road.logic.activity.hotpotjump.game.choose;

import com.yanqu.road.entity.autodata.hotpotjump.HotpotJumpUnit;
import com.yanqu.road.logic.activity.hotpotjump.game.JumpBoardGrid;
import com.yanqu.road.logic.activity.hotpotjump.game.eJumpDirection;

import java.util.ArrayList;
import java.util.List;

/**
 * 12 场面血量最少的怪物所在点
 */
public class HotpotJumpSkillChoose12 extends HotpotJumpSkillChoose {
    @Override
    public List<List<JumpBoardGrid>> chooseGrid() {
        List<List<JumpBoardGrid>> result = new ArrayList<>();

        List<HotpotJumpUnit> allAliveUnits = new ArrayList<>();
        for (HotpotJumpUnit jumpUnit : gameLogic.getGameData().getUnits()) {
            if (!jumpUnit.isDead()) {
                allAliveUnits.add(jumpUnit);
            }
        }

        allAliveUnits.sort((o1, o2) -> {
            int compare = Integer.compare(o1.getHeadPos().getHp(), o2.getHeadPos().getHp());
            if (compare == 0) {
                compare = Integer.compare(o2.getConfigId(), o1.getConfigId());
            }
            return compare;
        });
        int takeNum = skillRange.getRangeNum();
        for (int i = 0; i < allAliveUnits.size() && i < takeNum; i++) {
            HotpotJumpUnit unit = allAliveUnits.get(i);
            JumpBoardGrid grid = gameLogic.board.findGrid(unit.getHeadPos().getX(), unit.getHeadPos().getY());
            List<JumpBoardGrid> grids = gameLogic.calcRangeGrids(grid, skillRange, eJumpDirection.None);
            result.add(grids);
        }

        return result;
    }
}
